package com.dhl.fin.api.service;

import com.dhl.fin.api.common.util.MapUtil;
import com.dhl.fin.api.common.util.excel.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * @author CuiJianbo
 * @since 2023/8/13
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class FinancialDataAnalyseServiceImpl {


    @Autowired
    private JdbcTemplate jdbcTemplate;


    /**
     * 导入10年期国债
     */
    public void importCountryDebt() {

        List<Map> datas = ExcelUtil.getExcelFromLocal("D:\\Beck Work Space\\Personal\\stock\\金融数据\\国债\\国债2023年.xlsx");

        for (Map data : datas) {
            Double amount = MapUtil.getDouble(data, "10年");
            String date = MapUtil.getString(data, "日期");

            jdbcTemplate.execute(String.format("insert into t_stock_analyse_data values(%s,'%s',now(),'countryDebt')", amount, date));
        }
    }

    /**
     * 导入人民币汇率
     */
    public void importRMB() {


        List<Map> datas = ExcelUtil.getExcelFromLocal("D:\\Beck Work Space\\Personal\\stock\\金融数据\\人民币汇率\\人民币汇率.xlsx");

        for (Map data : datas) {
            Double amount = MapUtil.getDouble(data, "值");
            String date = MapUtil.getString(data, "时间");

            jdbcTemplate.execute(String.format("insert into t_stock_analyse_data values(%s,'%s',now(),'RMB')", amount, date));
        }
    }

    public void importGold(){

    }

}
